package com.sjd.web.api.account;

import com.sjd.common.core.controller.BaseController;
import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.page.TableDataInfo;
import com.sjd.mall.domain.SjdIntegralDetailDO;
import com.sjd.mall.domain.dto.account.InsertIntegralRequestDTO;
import com.sjd.mall.domain.dto.account.WxIntergralDetailResponseDTO;
import com.sjd.mall.service.account.AccountIntegralService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
  *@CalssName WxIntegralApi
  *@Description 小程序积分AP
  *@Authot genglong
  *@Date 2022/1/18 15:48
  *@Version 1.0
  **/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/integral")
@Api(value = "integral", tags = "小程序积分API")
public class WxIntegralApi extends BaseController {

    private final AccountIntegralService accountIntegralService;

    /**
     * 查询当天打卡状态
     */
    @ApiOperation(value = "查询当天打卡状态")
    @GetMapping("/queryClockStatus")
    public AjaxResult queryClockStatus() {
        try {
            return accountIntegralService.queryClockStatus();
        } catch (Exception e) {
            log.error("查询当天打卡状态出现异常，异常信息===>{}", e.getMessage());
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 打卡/升级土地
     */
    @ApiOperation(value = "打卡/升级土地")
    @PostMapping("/insertIntegralDetail")
    public AjaxResult insertIntegralDetail(@Validated @RequestBody InsertIntegralRequestDTO requestDTO) {
        try {
            return accountIntegralService.insertIntegralDetail(requestDTO);
        } catch (Exception e) {
            log.error("积分订单出现异常，异常信息===>{}", e.getMessage());
            return AjaxResult.error("积分订单出现异常");
        }
    }

    /**
     * 积分明细
     * @return
     */
    @ApiOperation(value = "积分明细")
    @GetMapping("/queryIntegrallist")
    public TableDataInfo queryIntegrallist() {
        startPage();
        List<WxIntergralDetailResponseDTO> resultList = accountIntegralService.queryIntegrallist();
        return getDataTable(resultList);
    }
}
